<?php
namespace app\api\controller;
use think\Input;
use think\Controller;
use app\admin\model\Users;
use app\common\controller\Base;
class User extends Base{
	public function delete($email){
        if (!empty($email)){
            $Users = new Users;
            if($Users->where(['email'=>$email])->delete()){
            	return $result = ['code'=>0,'msg'=>lang('success')];
            }
        }
        return $result = ['code'=>-1,'msg'=>lang("sorry, you don't have permission.")];
	}
	/*修改数据*/
	public function edit(){
		 if($this->request->isPost()){
	         $data = $this->request->post();
	         file_put_contents('123.log', json_encode($data),FILE_APPEND);
	         $data = $data['arg'];
	         $Users = new Users;
	         if($Users->where(['email'=>$data['condition']])->update($data)){
	         	return ['code'=>-1,'msg'=>lang('success')];
	         }
	      }
	      return ['code'=>-1,'msg'=>lang('fail')];
	}
	/*修改数据*/
	public function register(){
		 if($this->request->isPost()){
	         $data = $this->request->post();
	         $data = $data['arg'];
	         $Users = new Users;
	         $data['email'] = 'ddd'.$data['email'];
	         if($Users->where(['email'=>$data['email']])->count()){
	         	return ['code'=>-1,'msg'=>lang('this email has been used')];
	         }
	         if(empty($data['password'])){
	         	return ['code'=>-1,'msg'=>lang('password can not be blank')];
	         }
	         $data['pwd'] = $data['password'];
	         if($Users->data($data)->insert($data)){
	         	return ['code'=>1,'msg'=>lang('success')];
	         }
	      }
	      return ['code'=>-1,'msg'=>lang('fail')];
	}
	public function test(){
		$rows = db('compact_posts')->where('post_content',"like","%<!--codes_iframe-->%")->select();
		foreach($rows as $row){
			echo $post_content = preg_replace("/<!--codes_iframe-->(.*)<!--\/codes_iframe-->/", '', $row['post_content']);
			db('compact_posts')->where(['ID'=>$row['ID']])->update(['post_content'=>$post_content]);
		}
		exit('Finish');
		$s = '2018-12-13 12:59:00';
		$e = '2018-12-13 13:00:11';
		$endTime = strtotime($e);
		$startTime = strtotime($s);
		echo round(($endTime-$startTime)/86400);
		echo round(($endTime-$startTime)/(60));
		echo ($endTime-$startTime)%60;
		exit;
		
		print_r($ss);
	}
}